import { v4 as uuidv4 } from 'uuid'
/**
 * 将组件列表(树结构), 转换为map结构
 *
 * @param designCompList 组件列表
 * @returns key为组件id，value为组件配置实例
 */
export function convertDesignCompListToMap(designCompList: DesignComp[]) {
  const map = new Map<string, DesignComp>()
  doConvertDesignCompListToMap(map, designCompList)
  return map
}
function doConvertDesignCompListToMap(map: Map<string, DesignComp>, designCompList: DesignComp[]) {
  for (const item of designCompList) {
    map.set(item.id, item)
    if (item.children && item.children.length > 0) {
      doConvertDesignCompListToMap(map, item.children)
    }
  }
}
export function buildBaseConfigStyle(baseConfig: BaseConfigData) {
  if (!baseConfig) {
    return ''
  }
  let styleStr = ''
  if (baseConfig.width) {
    styleStr += `width:${baseConfig.width};`
  }
  if (baseConfig.height) {
    styleStr += `height:${baseConfig.height};`
  }
  if (baseConfig.bgColor) {
    styleStr += `background-color:${baseConfig.bgColor};`
  }
  if (baseConfig.style) {
    styleStr += `${baseConfig.style};`
  }
  // if (baseConfig.bgImg) {
  //   styleStr += `background-color:${baseConfig.height};`
  // }
  return styleStr
}
/**
 * 生成组件实例id
 * @param compFlag 组件的vue名称
 * @returns
 */
export function buildCompInstanceId(compFlag: string) {
  const compInstanceId = `${compFlag}-design-${uuidv4()}`
  return compInstanceId
}
